<template>
  <div class="wrapper">
    <!--                            使用v-if判断swiperList数组是有值-->
    <swiper :options="swiperOption" v-if="showSwiper">
    <!-- slides -->
    <swiper-slide v-for="item of swiperList" :key="item.id">
      <img class="swiper-img" alt="" :src='item.imgUrl'>
    </swiper-slide>
    <!-- Optional controls -->
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  props: {
    swiperList: Array
  },
  data() {
    return {
      notNextTick: true,
      // 设置轮播图
      swiperOption: {
        // pagination: ".swiper-pagination",
        // paginationType: "fraction",
        loop: true,
        autoplay: 1600, //播放间隔
        speed: 1200, // 速度
        autoplayDisableOnInteraction: false // 点击后不会阻止自动轮播
      }
    };
  },
  computed:{
    showSwiper(){
      return this.swiperList.length
    }
  }
};
</script>

<style lang="less" scoped>
.wrapper /deep/ .swiper-pagination-bullet-active {
  background-color: #fff;
}
.wrapper {
  width: 100%;
  height: 0;
  overflow: hidden;
  padding-bottom: 30.25%;
  .swiper-img {
    width: 100%;
  }
}
</style>